//
//  YTVideoViewController.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/11/22.
//

#import "YTVideoViewController.h"
#import "TBPlayer.h"
#import "ZScrollLabel.h"
#import <SJVideoPlayer/SJVideoPlayer.h>

@interface YTVideoViewController ()
@property (nonatomic ,strong) ZScrollLabel * scrollLabel;
@property (nonatomic ,strong) UIView * topview;
@property (nonatomic, strong) SJVideoPlayer *player;

@end

@implementation YTVideoViewController
#pragma mark - life cycle
- (void)viewDidLoad {
    
    SJVideoPlayer * player = [SJVideoPlayer player];
    self.player = player;
    [self.view addSubview:player.view];
    [player.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.offset(0);
        make.top.offset(0);
    }];
    SJVideoPlayer.updateResources(^(id<SJVideoPlayerControlLayerResources>  _Nonnull resources) {
        resources.progressTrackColor = [UIColor darkGrayColor];
        resources.progressTraceColor = KcolorHex(@"#3262FF");
    });
 
    
    self.player.onlyFitOnScreen = NO;
    self.player.automaticallyPerformRotationOrFitOnScreen = YES;
    self.player.needsFitOnScreenFirst = NO;
    ///一直显示控制层
//    [_player.controlLayerAppearManager keepAppearState];
//    _player.controlLayerAppearManager.disabled = YES;
    ///画中画按钮
    if (@available(iOS 14.0, *)) {
        self.player.defaultEdgeControlLayer.automaticallyShowsPictureInPictureItem = NO;
    }
    SJVideoPlayerURLAsset *asset = [SJVideoPlayerURLAsset.alloc initWithURL:[NSURL URLWithString:self.url]];
    asset.attributedTitle = [DTKTool AttributedStringWithStr:self.titleStr andNodeColor:UIColor.whiteColor andSeledColor:UIColor.whiteColor andFont:kCFont(18) andPattenr:@""] ;
    player.URLAsset = asset;
    [player play];
    
   
}

- (BOOL)shouldAutorotate {
    return NO;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [_player vc_viewDidAppear];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [_player vc_viewWillDisappear];
}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [_player vc_viewDidDisappear];
}
@end
